package com.lc.nlp4han.chunk;

import java.io.OutputStream;
import java.io.PrintStream;

/**
 * 	组块分析错误样本输出
 */
public class ChunkAnalysisErrorPrinter extends ChunkAnalysisEvaluateMonitor
{

	private PrintStream errOut;

	/**
	 * 构造方法
	 * 
	 * @param out
	 *            输出流
	 */
	public ChunkAnalysisErrorPrinter(OutputStream out)
	{
		errOut = new PrintStream(out);
	}

	@Override
	public void missclassified(AbstractChunkAnalysisSample reference, AbstractChunkAnalysisSample prediction)
	{
		errOut.println("样本的结果：" + reference);
		errOut.println("预测的结果：" + prediction);

		String[] actualChunks = reference.getTokens();
		String[] predictChunks = prediction.getTags();
		String errorInfo = "";

		if (actualChunks.length != predictChunks.length)
		{
			errorInfo += "组块标记长度不同";
		}
		else
		{
			for (int i = 0; i < actualChunks.length; i++)
			{
				if (!actualChunks[i].equals(predictChunks[i]))
					errorInfo += i + "-" + actualChunks[i] + "/" + predictChunks[i] + ", ";
			}

			if (!errorInfo.trim().equals(""))
				errorInfo = errorInfo.trim().substring(0, errorInfo.length() - 1);
		}
		errOut.println(errorInfo + "\n");
	}
}
